package net.oschina.app.pages;

import android.widget.Button;
import android.widget.EditText;

import net.oschina.app.SoloWrap;

/**
 * Created by Aaron on 2017/10/29.
 */

public class PageLogin {
    private SoloWrap soloWrap;

    public PageLogin(SoloWrap soloWrap){
        this.soloWrap = soloWrap;
    }

    public EditText getNameET(){
        return soloWrap.getEditText(0);
    }

    public EditText getPwdET(){
        return soloWrap.getEditText(1);
    }

    public Button getLoginBtn(){
        return (Button) soloWrap.findById("net.oschina.app:id/btn_login");
    }

    public void enterName(String name){
        soloWrap.enterText(getNameET(),name);
    }

    public void enterPwd(String pwd){
        soloWrap.enterText(getPwdET(),pwd);
    }

    public void clickLoginBtn(){
        soloWrap.click(getLoginBtn());
    }

    public void clearName(){
        soloWrap.clear(getNameET());
    }

    public void clearPwd(){
        soloWrap.clear(getPwdET());
    }

    public void login(String name,String pwd){
//        soloWrap.click(getNameET());
        clearName();
        enterName(name);
//        soloWrap.click(getPwdET());
        clearPwd();
        enterPwd(pwd);
        clickLoginBtn();
    }

    public boolean isLoginScreenOpened(){
        boolean result = false;
        if(getLoginBtn() != null){
            return getLoginBtn().isShown();
        }
        return false;
    }
}
